import React from 'react';
import { observer, inject } from 'mobx-react';
import WfTextarea from '../../public/wf-form-textarea/index';
import { getLabel } from '../../util/common';
import { withRouter } from 'react-router-dom';

@inject('wfLayoutStore')
@withRouter
@observer
export default class TextareaElement extends React.Component{
    doChangeEvent(value){
        const { fieldMark,wfLayoutStore } = this.props;
		wfLayoutStore.changeSingleFieldValue(fieldMark, {value: value});
	}
    render() {
        const { fieldid,fieldMark,fieldValue,viewAttr,fieldAttr,symbol,rowIndex,cellObj,fieldObj } = this.props;
        const { detailtype,isDetail,fieldlabel,fielddbtype } = fieldAttr;
        let textareaProps = { fieldid,viewAttr,fieldMark,detailtype,isDetail,fieldlabel,fielddbtype,value:fieldValue };
        const { variable } = fieldObj;
        if(viewAttr !== 1){   //可编辑空值显示的默认值
            textareaProps.emptyShowContent = variable.get("emptyShowContent") || getLabel(83869,"请输入");
        }
        textareaProps.textheight = "textheight" in fieldAttr ? fieldAttr.textheight : 4;
        textareaProps.length = "length" in fieldAttr ? fieldAttr.length : 4000;
        
        return(
            <WfTextarea
                {...textareaProps}
                onChange = {this.doChangeEvent.bind(this)}
            />
        )
    }
}